<template>
    <div class="example1-wrapper">
        <div class="inner">
            <bk-table
                style="margin-top:20px"
                height="530"
                :data="data"
                ref="table">
                <bk-table-column type="selection" width="60"></bk-table-column>
                <bk-table-column label="订单号" prop="orderid" sortable></bk-table-column>
                <bk-table-column label="商家名" prop="merealname" sortable></bk-table-column>
                <bk-table-column label="状态" prop="status"></bk-table-column>
                <bk-table-column label="价格" prop="total"></bk-table-column>
                <bk-table-column label="最新更新时间" prop="updatetime"></bk-table-column>
                <bk-table-column label="操作" width="150">
                    <template slot-scope="props">
                        <bk-button @click="lookinfo(props.row)" class="mr10" theme="primary" text>详情</bk-button>
                    </template>
                </bk-table-column>
            </bk-table>
        </div>
    </div>
</template>

<script>
    export default {
        data () {
            const user = sessionStorage.getItem('user')
            if (user) {
                const username = JSON.parse(user)
                this.username = username
            }
            this.getorders()
            return {
                username: '',
                mername: '',
                total: 0,
                digits: 1,
                data: [
                ]
            }
        },
        methods: {
            /**
             * 获取页面数据
             *
             * @return {Promise} promise 对象
             */
            getorders () {
                const qs = require('qs')
                this.axios({
                    url: '/getordering/',
                    method: 'post',
                    responseType: 'json',
                    data: qs.stringify({
                        username: JSON.parse(sessionStorage.getItem('user'))
                    })
                }).then(res => {
                    for (const i in res.data.result_data) {
                        const tmp = {
                            orderid: 0,
                            merealname: '',
                            total: 0,
                            status: '',
                            updatetime: ''
                        }
                        tmp.orderid = res.data.result_data[i].id
                        tmp.merealname = res.data.result_data[i].merchant_realname
                        tmp.total = res.data.result_data[i].total
                        tmp.status = res.data.result_data[i].status
                        tmp.updatetime = res.data.result_data[i].updatetime
                        this.$set(this.data, i, tmp)
                    }
                })
            },
            sourceFilterMethod (value, row, column) {
                const property = column.property
                return row[property] === value
            },
            statusFilterMethod (value, row, column) {
                const property = column.property
                return row[property] === value
            },
            lookinfo (row) {
                this.$router.push({
                    name: 'underway',
                    query: {
                        id: row.orderid
                    }
                })
            }
        }
    }
</script>

<style scoped>
    .bk-table-header .custom-header-cell {
        color: inherit;
        text-decoration: underline;
        text-decoration-style: dashed;
        text-underline-position: under;
    }
</style>
